package com.gis.dto;

import com.gis.enums.QualityReportEnum;
import lombok.Data;

import java.io.Serializable;


@Data
public class BiologyReportDTO implements Serializable {

    private Integer stationId;
    private String name;
    private Float latitude;
    private Float longitude;
    // 汞
    private Float mercury;
    // 镉
    private Float cadmium;
    // 铅
    private Float lead;
    // 铬
    private Float chromium;
    // 砷
    private Float arsenic;
    // 铜
    private Float copper;
    // 锌
    private Float zinc;
    // 石油烃
    private Float tph;


    // 汞
    private int classMercury;
    // 镉
    private int classCadmium;
    // 铅
    private int classLead;
    // 铬
    private int classChromium;
    // 砷
    private int classArsenic;
    // 铜
    private int classCopper;
    // 锌
    private int classZinc;
    // 石油烃
    private int classTph;


    public void setClassMercury() {
        this.classMercury = classifyBiologyQuality(0, this.mercury).getCode();
    }

    public void setClassCadmium() {
        this.classCadmium = classifyBiologyQuality(1, this.cadmium).getCode();
    }

    public void setClassLead() {
        this.classLead = classifyBiologyQuality(2, this.lead).getCode();
    }

    public void setClassChromium() {
        this.classChromium = classifyBiologyQuality(3, this.chromium).getCode();
    }

    public void setClassArsenic() {
        this.classArsenic = classifyBiologyQuality(4, this.arsenic).getCode();
    }

    public void setClassCopper() {
        this.classCopper = classifyBiologyQuality(5, this.copper).getCode();
    }

    public void setClassZinc() {
        this.classZinc = classifyBiologyQuality(6, this.zinc).getCode();
    }

    public void setClassTph() {
        this.classTph = classifyBiologyQuality(7, this.tph).getCode();
    }

    /**
     * 参数分类
     */
    private final static double[][] biologyStandards = {
            {0.05, 0.30},  // 汞
            {0.2, 5.0},  // 镉
            {0.1, 6.0},  // 铅
            {0.5, 6.0},  // 铬
            {1.0, 8.0},  // 砷
            {10, 50},  // 铜
            {20, 100},  // 锌
            {15, 80}  // 石油烃
    };
    private QualityReportEnum classifyBiologyQuality(int index, Float param) {
        if (param < 0) return QualityReportEnum.FIRST_CLASS;
        if (param <= biologyStandards[index][0]) return QualityReportEnum.FIRST_CLASS;
        if (param <= biologyStandards[index][1]) return QualityReportEnum.SECOND_CLASS;
        return QualityReportEnum.THIRD_CLASS;
    }


    /**
     * 综合评价方法
     * @return
     */
    public int getComprehensiveClass() {
        int poorCount = 0;
        int mediumCount = 0;

        if (classMercury == 3) poorCount++;
        if (classCadmium == 3) poorCount++;
        if (classLead == 3) poorCount++;
        if (classChromium == 3) poorCount++;
        if (classArsenic == 3) poorCount++;
        if (classCopper == 3) poorCount++;
        if (classZinc == 3) poorCount++;
        if (classTph == 3) poorCount++;

        if (classMercury == 2) mediumCount++;
        if (classCadmium == 2) mediumCount++;
        if (classLead == 2) mediumCount++;
        if (classChromium == 2) mediumCount++;
        if (classArsenic == 2) mediumCount++;
        if (classCopper == 2) mediumCount++;
        if (classZinc == 2) mediumCount++;
        if (classTph == 2) mediumCount++;

        if (poorCount == 0 && mediumCount <= 2) {
            return 1;
        } else if (poorCount == 0 && mediumCount > 2) {
            return 2;
        } else {
            return 3;
        }
    }

}
